/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Manish Mehta 
 												
Class							:				CBRIndexEntry
 
Function						: 				A simple CBRIndexEntry class
****************************************************************************/
package trace;

import java.io.IOException;
import java.io.Serializable;
import java.io.StringReader;

import org.w3c.dom.Node;

import planninglanguage.goals.Goal;
import base.CBLILRModule;
import base.WargusGameState;

public class CBRIndexEntry implements Serializable{
	private Goal m_goal;
	private transient WargusGameState m_gameState;
	
	public CBRIndexEntry(Goal a_goal, WargusGameState a_gamestate)
	{
		m_goal = a_goal;
		m_gameState = a_gamestate;
	}
	public Goal getGoal()
	{
		return m_goal;
	}
	public WargusGameState getGameState()
	{
		return m_gameState;
	}
	public void setGoal( Goal a_goal)
	{
		m_goal = a_goal;
	}
	public void setGameState(WargusGameState a_gameState)
	{
		m_gameState = a_gameState;
	}
	// TODO use XMLWriter
	private void writeObject(java.io.ObjectOutputStream out) throws IOException, ClassCastException, ClassNotFoundException, InstantiationException, IllegalAccessException
	{
		out.defaultWriteObject();
		out.writeObject("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <gamestate xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"Wargus-trace.xsd\">");
		// TODO: Write the state
		// m_gameState.writeXML(out);
		out.writeObject("</gamestate>");
		out.flush();

	}
	private void readObject(java.io.ObjectInputStream in) throws IOException,
	    ClassNotFoundException, ClassCastException, InstantiationException, IllegalAccessException
	{
		in.defaultReadObject();
		String str = (String)in.readObject();
		StringReader rd = new StringReader(str);
		System.out.println("Game State Serialized is" + str);
		Node n = CBLILRModule.ReadXMLfromReader(rd);		
		m_gameState = WargusGameState.ImportXMLGameState(n, 0);
	}
	
}
